<template>
  <div id="seat">
    <h1 class="title">席位透视</h1>
    <div v-show="!loading">
      <div v-show="show">
        <div class="upper">
          <div class="upper-top">
            <div class="upper-top_left">
              <p class="name">席位名称</p>
              <p class="content">{{ detailObj.branchName }}</p>
            </div>
            <div class="upper-top_right">
              <div>
                <span>席位类型</span>
                <span class="text-box">{{ detailObj.seatType }}</span>
              </div>
            </div>

            <div v-show="isVersion">
              <div
                class="attention"
                @click="save(detailObj, '0')"
                v-if="saveType.length == 0"
              >
                <img
                  :src="PIC_URL + '/tlbypcWeb/dragonTigerNew/wgz.png'"
                  alt=""
                  class="saveImg"
                />
                <span>+ 关注</span>
              </div>
              <div class="attention" @click="save(detailObj, '1')" v-else>
                <img
                  :src="PIC_URL + '/tlbypcWeb/dragonTigerNew/ygz.png'"
                  alt=""
                  class="saveImg"
                />
                <span> 已关注</span>
              </div>
            </div>
          </div>
          <div class="upper-middle">
            <span class="name">资金规模</span>
            <span class="content">
              {{ detailObj.strengthType }}
              {{ detailObj.capitalScale | format }}</span
            >
          </div>
          <div class="upper-bottom">
            <div class="upper-bottom_left">
              <div class="star">
                短线评级
                <el-rate
                  class="rate"
                  disabled-void-color="#4E505C"
                  v-model="detailObj.gradeShort"
                  disabled
                >
                </el-rate>
              </div>
              <div>
                操作风格 <span class="cont">{{ detailObj.tradeStyle }}</span>
              </div>
            </div>
            <div class="upper-bottom_right">
              <div class="star">
                中线评级
                <el-rate
                  class="rate"
                  disabled-void-color="#4E505C"
                  v-model="detailObj.gradeMiddle"
                  disabled
                >
                </el-rate>
              </div>
              <div>
                操作频率
                <span class="cont">{{ detailObj.operateFrequency }}</span>
              </div>
            </div>
          </div>
        </div>
        <div class="middle" v-show="showMid">
          <div class="middle-left">
            <h2>
              席位成功率 <span>{{ success }}</span>
            </h2>
            <div class="chart"><div id="container"></div></div>
          </div>
        </div>
        <div v-show="!showMid" class="data-wushuju"></div>
        <div
          class="middle"
          v-show="showMid"
          style="border-top: 1px solid #27282e"
        >
          <div class="middle-right">
            <h2>
              跟买收益率 <span>{{ yied }}</span>
            </h2>
            <div class="chart">
              <div id="container3"></div>
            </div>
          </div>
        </div>
        <div v-show="!showMid" class="data-wushuju"></div>
      </div>
      <div class="showBox" v-show="!show">
        <div class="wushuju"></div>
      </div>
    </div>

    <div class="loadingBox" v-show="loading">
      <div class="loading"></div>
      <p>数据加载中...</p>
    </div>
  </div>
</template>
<script>
import { getBranch, save, attention } from "../api/index";
import * as Highcharts from "highcharts";
import highchartsMore from "highcharts/highcharts-more";
highchartsMore(Highcharts);

import { numberFormat, getUrlParams } from "../script/util";

var href = window.location.href;
var match = href.match(/id=([^\&]*)\&?.*/);
var code = match ? match[1] : "";
var chart;
function success(val) {
  val = Number(val);
  return val < 40 ? "较低" : "较高";
}
function yied(val) {
  val = Number(val);
  var text = "";
  if (val >= 2.5) {
    text = "较高";
  } else if (val >= 0 && val < 2.5) {
    text = "一般";
  } else {
    text = "较低";
  }
  return text;
}
export default {
  data() {
    return {
      centralToken:
        "CN,4G3Btpq5vZcSV4X,tAxOeKWefRY8,Ufb8oobyMA48jD6GxizfWHC5lk32VEHCYcZr6IjvNExBkhopDhFSWx0sZsRK3xp,7O.z.vBD5BktwRMDAuUjWk9dgIyR.5gQUodnKcBjJz7bD.cKUqyJ3Ea4EO,kpmQQtyCxutjc3w8DD4YvUbDs0uAURgQz6rAZzqLgdIOjzPs_",
      data1: [],
      data2: [],
      type0: true,
      type1: true,
      showMid: true,
      detailObj: {},
      moneyList: [],
      countList: [],
      success: "",
      yied: "",
      tickInterval1: "",
      tickInterval2: "",
      show: false,
      loading: true,
      saveType: [], //关注状态
      version: "",
      isVersion: false,
    };
  },
  filters: {
    format(val) {
      return numberFormat(val);
    },
  },
  mounted() {
    const { version } = getUrlParams();
    window.remoteSeatFunc = (code, _val, token, version) => {
      this.centralToken = token;
      this.version = version;
      this.getBranch(code);
      // 判断是否是关注
      const redFruits = ["4", "5", "11", "101"];
      if (
        this.version == "4" ||
        this.version == "5" ||
        this.version == "11" ||
        this.version == "101"
      ) {
        this.isVersion = true;
      }
    };
    window.addEventListener("resize", this.resizeHandler);
    this.resizeHandler();
    const redFruits = ["4", "5", "11", "101"];
    if (redFruits.includes(version)) {
      this.isVersion = true;
    }
    this.getBranch(code);
  },
  methods: {
    resizeHandler() {
      let windowWidth = document.body.offsetWidth;
      let charts = document.getElementsByClassName("chart");
      Object.values(charts).forEach((ele) => {
        ele.style.width = Math.floor(windowWidth / 1.1) + 30 + "px";
      });
    },

    async getBranch(code) {
      await getBranch({ id: code }).then((back) => {
        if (back.status == 1) {
          let res = back.data;

          this.detailObj = res;
          this.attention(res.branchCode);
          this.success = success(res.successRateNext);
          this.yied = yied(res.pricechgAvgNext);
          var list1 = [],
            list2 = [],
            list3 = [],
            list4 = [];
          list3.push(res.successRateNext);
          list3.push(res.successRateDay3);
          list3.push(res.successRateDay5);
          list3.push(res.successRateDay10);
          list3.push(res.successRateDay20);

          list4.push(res.pricechgAvgNext);
          list4.push(res.pricechgAvgDay3);
          list4.push(res.pricechgAvgDay5);
          list4.push(res.pricechgAvgDay10);
          list4.push(res.pricechgAvgDay20);
          var total1 = list3.reduce((total, num) => total + num);
          var total2 = list4.reduce((total, num) => total + num);
          if (total1 == 0 && total2 == 0) {
            this.showMid = false;
          } else {
            this.showMid = true;
            this.data1 = list3.map(
              (item) => Math.round(item * 100 * 100) / 100
            );
            this.data2 = list4.map(
              (item) => Math.round(item * 100 * 100) / 100
            );
            this.drow1("container", this.data1);
            this.drow1("container3", this.data2);
          }
          this.show = true;
          this.loading = false;
        }
      });
    },
    drow1(el, data, tick) {
      Highcharts.chart(el, {
        chart: {
          type: "column",
          spacing: [30, 5, 5, 5],
          plotBorderWidth: 1,
          backgroundColor: "#090910",
          borderColor: "#090910",
          plotBorderColor: "#1E2127",
          height: "240px",
          borderWidth: 1,
        },
        legend: { enabled: false },
        credits: { enabled: false },
        title: { text: null },
        xAxis: {
          categories: ["次日", "三日", "五日", "十日", "二十日"],
          lineWidth: 0,
        },
        yAxis: {
          tickAmount: 6,
          startOnTick: false,
          endOnTick: false,
          gridLineColor: "#1E2127",
          title: {
            text: "单位：%",
            align: "high",
            offset: 5,
            rotation: 0,
            y: -10,
            style: {
              fontWeight: "400",
              fontSize: "14px",
              color: "#999",
              textOutline: "none",
            },
          },
          labels: {
            format: "{value}",
          },
          maxPadding: 0.2,
        },
        plotOptions: {
          series: {
            color: "#D4302C",
            borderWidth: 0,
            negativeColor: "#4cbb5b",
            dataLabels: {
              enabled: true,
              // crop:false,
              // overflow:'none',
              y: -2,
              style: {
                fontWeight: "400",
                fontSize: "13px",
                color: "#ffffff",
                // paddingBottom: "5px",
                textOutline: "none",
              },
            },
          },
        },
        tooltip: {
          enabled: false,
        },
        series: [
          {
            data: data,
          },
        ],
      });
    },
    async save(item, type) {
      const { token } = getUrlParams();
      await save({
        centralToken: this.centralToken,
        id: this.saveType.id,
        branchCode: item.branchCode,
        branchName: item.branchName,
        dr: type,
      }).then((res) => {
        if (res.status == 1) {
          this.attention(item.branchCode);
        }
      });
    },
    // 取消关注
    async quSave(item) {
      const { token } = getUrlParams();
      await save({
        centralToken: this.centralToken,
        id: this.saveType.id,
        branchCode: item.branchCode,
        branchName: item.branchName,
        dr: 0,
      }).then((res) => {
        if (res.status == 1) {
          this.attention(item.branchCode);
        }
      });
    },
    //关注
    async attention(branchCode) {
      const { token } = getUrlParams();
      await attention({
        centralToken: this.centralToken,
        branchCode: branchCode,
      }).then((res) => {
        if (res.status == 1) {
          this.saveType = res.data;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
#seat {
  width: 100%;
  background: #090910;
}
h2 {
  color: #bcbfc4;
  font-size: 16px;
  span {
    margin-left: 16px;
    color: #ff8d27;
    box-sizing: border-box;
  }
}
.showBox {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  .wushuju {
    margin: 0 auto;
    margin-top: 183px;
    width: 401px;
    height: 233px;
    background: url($PIC_URL + "/tlbypcWeb/dragonTigerNew/zanwushuju.png")
      no-repeat;
    background-size: 100%;
  }
}
.loadingBox {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  .loading {
    margin: 0 auto;
    margin-top: 183px;
    width: 192px;
    height: 192px;
    background: url($PIC_URL + "/tlbypcWeb/dragonTigerNew/loading.gif")
      no-repeat;
    background-size: 100%;
  }
  p {
    font-size: 18px;
    color: #bbbfc3;
    margin-top: 28px;
  }
}

.title {
  height: 48px;
  padding-left: 20px;
  font-size: 20px;
  line-height: 48px;
  color: #ff8a00;
  background: rgba(39, 40, 46, 1);
  border: 1px solid rgba(0, 0, 0, 1);
  box-sizing: border-box;
}
.upper {
  padding: 20px;
  color: #bcbfc4;
  font-size: 16px;
  border-bottom: 1px solid #27282e;
  box-sizing: border-box;
  .upper-top {
    display: flex;
    margin-bottom: 15px;
    .upper-top_left {
      display: flex;
      width: 50%;
      .name {
        width: 64px;
        margin-right: 18px;
      }
      .content {
        width: 208px;
        color: #f4f636;
      }
    }
    .upper-top_right {
      width: 30%;
      .text-box {
        display: inline-block;
        margin-left: 16px;
        width: 80px;
        height: 21px;
        line-height: 21px;
        text-align: center;
        background: #f24e36;
        border-radius: 2px;
        font-size: 15px;
        color: #fff;
      }
    }
    //关注按钮
    .attention {
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #d03536;
      line-height: 28px;
      cursor: pointer;
      .saveImg {
        display: inline-block;
        width: 16px;
        height: 16px;

        vertical-align: -3px;
      }
    }
  }
  .upper-middle {
    margin-bottom: 15px;
    .name {
      margin-right: 16px;
    }
    .content {
      color: #ff8d27;
    }
  }
  .upper-bottom {
    display: flex;
    justify-content: space-between;
    .cont {
      color: #fff;
      margin-left: 16px;
    }
    .star {
      display: flex;
      align-items: center;
      .rate {
        margin-left: 20px;
      }
    }

    .upper-bottom_left,
    .upper-bottom_right {
      width: 50%;
      div {
        margin-bottom: 15px;
        &:last-child {
          margin-bottom: 0;
        }
      }
    }
  }
}
.middle {
  display: flex;
  justify-content: center;
  padding: 20px 0;
  box-sizing: border-box;
}
.data-wushuju {
  margin: 0 auto;
  margin-top: 40px;
  width: 301px;
  max-width: 301px;
  height: 176px;
  background: url($PIC_URL + "/tlbypcWeb/dragonTigerNew/littleshuju.png")
    no-repeat;
  background-size: 100%;
}
.lower {
  border-top: 1px solid #27282e;
  height: 352px;
  padding: 20px;
  position: relative;
  box-sizing: border-box;
  .types {
    position: absolute;
    top: 45px;
    left: 35%;
    z-index: 99;
    color: #999999;
    font-size: 14px;
    line-height: 25px;
    justify-content: center;
    .item {
      margin-right: 30px;
      position: relative;
    }
    span {
      cursor: pointer;
      height: 27px;
      .box {
        display: inline-block;
        width: 10px;
        height: 10px;
        margin-right: 5px;
        background: #2c6bd4;
        position: relative;
        top: 1px;
      }
      .red {
        background: #d4302c;
      }
      .name {
        position: relative;
        top: 1px;
      }
      .icon {
        display: inline-block;
        width: 14px;
        height: 14px;
        border-radius: 50%;
        border: 1px solid #999999;
        position: relative;
        top: 3px;
        margin-right: 6px;
        box-sizing: border-box;
      }

      &.active {
        color: #fff;
        .icon {
          box-sizing: border-box;
          border: 1px solid #ff4e39;
          position: relative;
          text-align: center;
          top: 6px;
          &::before {
            content: "";
            display: inline-block;
            width: 6px;
            height: 6px;
            border-radius: 50%;
            position: relative;
            top: -8px;
            background: #ff4e39;
          }
        }
        .name {
          position: relative;
          top: 0;
        }
        .box {
          position: relative;
          top: 0px;
        }
      }
    }
  }
}
#container,
#container3 {
    min-width: 470px;
//   width: 100%;
  height: 400px;
}
</style>

<style>
.el-rate__item {
  width: 20px;
  height: 20px;
}
</style>
